package top.saodisheng.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.saodisheng.pojo.Staff;
import top.saodisheng.pojo.Vehicle;
import top.saodisheng.service.VehicleService;
import top.saodisheng.util.Page4Navigator;

/**
 * Description:
 *
 * @author 扫地生_saodisheng
 */
@RestController
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("/vehicles")
    public Page4Navigator<Vehicle> list(@RequestParam(value = "start", defaultValue = "0") int start,
                                        @RequestParam(value = "size", defaultValue = "5") int size) {
        start = start < 0 ? 0 : start;
        Page4Navigator<Vehicle> page = vehicleService.list(start, size, 5);
        return page;
    }
    // 获取一个用户
    @GetMapping("/vehicles/{id}")
    public Vehicle get(@PathVariable("id") int id) {
        return vehicleService.get(id);
    }

    // 删除一个用户
    @DeleteMapping("/vehicles/{id}")
    public String delete(@PathVariable("id")int id) {
        vehicleService.delete(id);
        return null;
    }
    // 添加一个用户
    @PostMapping("/vehicles")
    public Object add(@RequestBody Vehicle bean) {
        vehicleService.add(bean);
        return bean;
    }

    // 更新用户
    @PutMapping("/vehicles")
    public Object update(@RequestBody Vehicle bean) {
        vehicleService.update(bean);
        return bean;
    }
}
